unit DataModule_Controle;

interface

uses
  System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, Datasnap.DBClient,
  Datasnap.Provider, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  Data.FMTBcd, Data.SqlExpr;

type
  TDM_Controle = class(TDataModule)
    DSPControle: TDataSetProvider;
    CDSControle: TClientDataSet;
    CDSControleVALOR: TIntegerField;
    CDSControleTABELA: TStringField;
    SQLControle: TSQLDataSet;
  private
    { Private declarations }
  public
    { Public declarations }

    function retornaID (tabela : string) : integer;
  end;

var
  DM_Controle: TDM_Controle;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

uses DataModule_Conexao;

{$R *.dfm}

{ TDataModule2 }

function TDM_Controle.retornaID(tabela: string): integer;
var
  i : Integer;
begin
  CDSControle.Close;
  CDSControle.Params[0].AsString := tabela;
  CDSControle.Open;

  CDSControle.Edit;
  i := CDSControleVALOR.AsInteger + 1;

  CDSControleVALOR.AsInteger := i;

  CDSControle.Post;
  CDSControle.ApplyUpdates(0);

  Result := i;
end;

end.
